﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:COL_MAIN
	/// </summary>
	public partial class COL_MAIN : BaseDAL<GSLMS.Entity.TB_COL_MAIN>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public COL_MAIN()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_COL_MAIN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANNO", model.LOANNO),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_ISUNWORKCOL", model.ISUNWORKCOL),
								new OracleParameter("P_LASTCOLDATE", model.LASTCOLDATE),
								new OracleParameter("P_NEXTDATE", model.NEXTDATE),
								new OracleParameter("P_IMPORTANCE", model.IMPORTANCE),
								new OracleParameter("P_PROMISEDATE", model.PROMISEDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_COLLEVEL", model.COLLEVEL),
								new OracleParameter("P_COLBY", model.COLBY),
								new OracleParameter("P_COLBYID", model.COLBYID)};
  
			for (int i = 0; i < 18; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_main_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_COL_MAIN model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LOANNO", model.LOANNO),
								new OracleParameter("P_CUSTNAME", model.CUSTNAME),
								new OracleParameter("P_CUSTNO", model.CUSTNO),
								new OracleParameter("P_PRODUCTNAME", model.PRODUCTNAME),
								new OracleParameter("P_PRODUCTID", model.PRODUCTID),
								new OracleParameter("P_ISUNWORKCOL", model.ISUNWORKCOL),
								new OracleParameter("P_LASTCOLDATE", model.LASTCOLDATE),
								new OracleParameter("P_NEXTDATE", model.NEXTDATE),
								new OracleParameter("P_IMPORTANCE", model.IMPORTANCE),
								new OracleParameter("P_PROMISEDATE", model.PROMISEDATE),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_COLLEVEL", model.COLLEVEL),
								new OracleParameter("P_COLBY", model.COLBY),
								new OracleParameter("P_COLBYID", model.COLBYID)};
  
			for (int i = 0; i < 18; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_main_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_main_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_COL_MAIN DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_COL_MAIN model = new GSLMS.Entity.TB_COL_MAIN();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["LOANNO"]!=null && dr["LOANNO"].ToString()!="")
				{
					model.LOANNO=dr["LOANNO"].ToString();
				}
				if(dr["CUSTNAME"]!=null && dr["CUSTNAME"].ToString()!="")
				{
					model.CUSTNAME=dr["CUSTNAME"].ToString();
				}
				if(dr["CUSTNO"]!=null && dr["CUSTNO"].ToString()!="")
				{
					model.CUSTNO=dr["CUSTNO"].ToString();
				}
				if(dr["PRODUCTNAME"]!=null && dr["PRODUCTNAME"].ToString()!="")
				{
					model.PRODUCTNAME=dr["PRODUCTNAME"].ToString();
				}
				if(dr["PRODUCTID"]!=null && dr["PRODUCTID"].ToString()!="")
				{
					model.PRODUCTID=OracleHelper.ToLong(dr["PRODUCTID"].ToString());
				}
				if(dr["ISUNWORKCOL"]!=null && dr["ISUNWORKCOL"].ToString()!="")
				{
                    model.ISUNWORKCOL = OracleHelper.ToInt(dr["ISUNWORKCOL"].ToString());
				}
				if(dr["LASTCOLDATE"]!=null && dr["LASTCOLDATE"].ToString()!="")
				{
					model.LASTCOLDATE=DateTime.Parse(dr["LASTCOLDATE"].ToString());
				}
				if(dr["NEXTDATE"]!=null && dr["NEXTDATE"].ToString()!="")
				{
					model.NEXTDATE=DateTime.Parse(dr["NEXTDATE"].ToString());
				}
				if(dr["IMPORTANCE"]!=null && dr["IMPORTANCE"].ToString()!="")
				{
					model.IMPORTANCE=dr["IMPORTANCE"].ToString();
				}
				if(dr["PROMISEDATE"]!=null && dr["PROMISEDATE"].ToString()!="")
				{
					model.PROMISEDATE=DateTime.Parse(dr["PROMISEDATE"].ToString());
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["COLLEVEL"]!=null && dr["COLLEVEL"].ToString()!="")
				{
					model.COLLEVEL=dr["COLLEVEL"].ToString();
				}
				if(dr["COLBY"]!=null && dr["COLBY"].ToString()!="")
				{
					model.COLBY=dr["COLBY"].ToString();
				}
				if(dr["COLBYID"]!=null && dr["COLBYID"].ToString()!="")
				{
					model.COLBYID=OracleHelper.ToLong(dr["COLBYID"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_COL_MAIN GetByID(long ID)
		{
			GSLMS.Entity.TB_COL_MAIN sModel = new GSLMS.Entity.TB_COL_MAIN();
			string sql = "";
			sql = "select * from TB_COL_MAIN where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_COL_MAIN> GetList(GSLMS.Entity.TB_COL_MAIN searchParam)
		{
			var list=new List<GSLMS.Entity.TB_COL_MAIN>();
			DataTable dt = null;
			string tblName = "TB_COL_MAIN";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_COL_MAIN model = new GSLMS.Entity.TB_COL_MAIN();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

